#ifndef SUBJECT_LIB_H_
#define SUBJECT_LIB_H_

#include "Course.h"
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <sstream>

Course Add_Course(string s){
	string i_c_id, i_s_id, i_l_id, i_room, i_time, temp;
	short i_sem;
	int mark;
	
	//course id
	mark = s.find("::");
	i_c_id = s.substr(0,mark);

	//subject id
	temp = s.substr(mark+2);
	mark = temp.find("::");
	i_s_id = temp.substr(0,mark);

	//lecturer id
	temp = temp.substr(mark+2);
	mark = temp.find("::");
	i_l_id = temp.substr(0,mark);

	//sem
	temp = temp.substr(mark+2);
	mark = temp.find("::");
	i_sem = atoi(temp.substr(0,mark).c_str());

	//room
	temp = temp.substr(mark+2);
	mark = temp.find("::");
	i_room = temp.substr(0,mark);

	//time
	i_time = temp.substr(mark+2);

	Course S(i_c_id, i_s_id, i_l_id, i_sem, i_room, i_time);
	return S;
}


void ReadStudent(string _file, Course l[], int &numCourse){
               ifstream fin;
               fin.open(_file.c_str());
               if(!fin.is_open()){
                       cout<<"Cannot open file.\n";
                       exit(1);
               }else{
                              string s = "";
                              while (getline(fin, s)){
                                l[numCourse] = Add_Course(s);
								numCourse++;
                              }
                              fin.close();
               }
}
/*
void WriteOut(string _file, Course l[], int &numberStudent){
               ofstream fout;
               fout.open(_file.c_str());
               for (int i=0 ; i<numberStudent ; i++){
                              fout<<l[i].get_id()<<":"<<l[i].get_fname()<<":"<<l[i].get_dob()<<":"<<l[i].get_addr()<<":"<<l[i].get_year()<<":"<<l[i].get_program()<<":"<<l[i].get_classname()<<endl;
               }
               fout.close();
}*/
#endif
